<template>
	<view>
		<view class="content">
			<van-empty v-if="!listData.length" image="error" description="暂时没有数据" />
			<view class="aa" v-for="item,index in listData" :key="index">
				<h3>{{item.test_name}}</h3>
				<van-collapse v-model="listData[index].activeNames">
					<van-collapse-item title="单选题" name="1">
						<text v-if="!item.single_wrong.length">没有错题</text>
						<view v-for="single_wrong,index1 in item.single_wrong" class="bb" :key="index1">
							<van-collapse v-model="listData[index].single_wrong[index1].activeNames">
								<text class="ff">题目：{{single_wrong.single.single_name}}</text>
								<van-collapse-item title="选项" name="2">
									<ul>
										<li>A：{{single_wrong.single.A}}</li>
										<li>B：{{single_wrong.single.B}}</li>
										<li>C：{{single_wrong.single.C}}</li>
										<li>D：{{single_wrong.single.D}}</li>
									</ul>
								</van-collapse-item>
								<view class="solution">
									<text class="ff">
										你的答案：<b class="ss">{{single_wrong.wrong_key}}</b>
									</text>
								<text class="ff">正确答案：{{single_wrong.single.right_key}}</text></view>
							</van-collapse>
						</view>
					</van-collapse-item>
					<van-collapse-item title="多选题" name="3">
						<text v-if="!item.selection_wrong.length">没有错题</text>
						<view v-for="selection_wrong,index1 in item.selection_wrong" class="bb" :key="index1">
							<van-collapse v-model="selection_wrong.activeNames">
								<text class="ff">题目：{{selection_wrong.selection.selection_name}}</text>
								<van-collapse-item title="选项" :name="4+index">
									<ul>
										<li>A：{{selection_wrong.selection.A}}</li>
										<li>B：{{selection_wrong.selection.B}}</li>
										<li>C：{{selection_wrong.selection.C}}</li>
										<li>D：{{selection_wrong.selection.D}}</li>
									</ul>
								</van-collapse-item>
								<view class="solution"><text class="ff">你的答案：<b
											class="ss">{{selection_wrong.wrong_key|aa}}</b></text><text
										class="ff">正确答案：{{selection_wrong.selection.right_key|aa}}</text></view>
							</van-collapse>
						</view>
					</van-collapse-item>
					<van-collapse-item title="判断题" :name="5+index">
						<text v-if="!item.judge_wrong.length">没有错题</text>
						<view v-for="judge_wrong,index2 in item.judge_wrong" class="bb" :key="index2">
							<van-collapse v-model="listData[index].judge_wrong[index2].activeNames">
								<text class="ff">题目：{{judge_wrong.judge.judge_name}}</text>
								<view class="solution"><text class="ff">你的答案：<b
											class="ss">{{judge_wrong.wrong_key}}</b></text><text
										class="ff">正确答案：{{judge_wrong.judge.right_key}}</text></view>
							</van-collapse>
						</view>
					</van-collapse-item>
				</van-collapse>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getStudentAppWrongs
	} from '@/api/user'
	export default {
		data() {
			return {
				listData: true,
				activeNames: []
			}
		},
		created() {
			this.getListData()
		},
		onShow() {
			this.getListData()
		},
		filters: {
			aa: function(data) {
				let ff = ""
				if (typeof data == 'object') {
					data.forEach(item => {
						ff += item
					})
					return ff
				}
				if(typeof data == 'string'){
					// console.log(data.match(/[abc]/g));
					data=JSON.parse(data)
					data.forEach(item => {
						ff += item
					})
					return ff
				}
			}
		},
		//用户下拉
		onPullDownRefresh() {
			this.getListData()
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		methods: {
			getListData() {
				getStudentAppWrongs({
					key: this.$store.getters.student_id
				}).then(res => {
					res.data.data.forEach(item => {
						item.activeNames = []
						// item.judge_wrong = item.judge_wrong
						item.judge_wrong.forEach(jw => {
							jw.activeNames = []
							if (jw.judge.right_key == "1") {
								jw.judge.right_key = "对"
							} else {
								jw.judge.right_key = "错"
							}
							if (jw.wrong_key) {
								jw.wrong_key = "对"
							} else {
								jw.wrong_key = "错"
							}
						})
						// item.selection_wrong = item.selection_wrong
						item.selection_wrong.forEach(sw => {
							sw.activeNames = []
						})
						item.single_wrong.forEach(iw => {
							iw.activeNames = []
						})
					})
					this.listData = res.data.data
				}).catch(err => {
					this.listData = false
				})
			},
			onClickLeft() {
				// uni.navigateBack({
				// 	delta: 2,
				// 	animationType: 'slide-out-left',
				// 	animationDuration: 10000
				// })
			}
		}
	}
</script>

<style>
	.aa {
		padding: 10rpx 0;
	}

	.bb {
		margin: 20rpx 0;
	}

	.ff {
		color: #606266;
	}

	.ss {
		color: red;
	}

	.content {
		padding: 20rpx;
	}

	h3 {
		color: #303133;
		padding: 20rpx 0;
	}

	.solution {
		display: flex;
		justify-content: space-between;
	}

	.van-hairline--top-bottom::after {
		border: none;
		border-bottom: #ebedf0 solid 1px;
	}
</style>
